/**
 * Author: Lily Jiang
 * Create Time: 2019/9/3
 * Description:
 */

import {createAction} from 'redux-actions'

export const updateUserInfo = (userInfo) => ({
    type: 'updateUserInfo',
    payload: userInfo
})

export const updateAppSetting = (setting) => ({
    type: 'updateAppSetting',
    payload: setting
})

//  更换主题
export const changeTheme = (themeType) => dispatch => {
    if (themeType === 'night') {
        document.getElementsByTagName('body')[0].style.setProperty('--theme-ff-to-1a','#1a1a1a');
        document.getElementsByTagName('body')[0].style.setProperty('--theme-33-to-99','#999999');
        document.getElementsByTagName('body')[0].style.setProperty('--theme-99-to-66','#666666');
        document.getElementsByTagName('body')[0].style.setProperty('--theme-f6-to-2f','#2f2f2f');
        document.getElementsByTagName('body')[0].style.setProperty('--theme-ed-to-44','#444444');
        document.getElementsByTagName('body')[0].style.setProperty('--theme-f6-to-00','#000000');
    } else if (themeType === 'day') {
        document.getElementsByTagName('body')[0].style.setProperty('--theme-ff-to-1a','#ffffff');
        document.getElementsByTagName('body')[0].style.setProperty('--theme-33-to-99','#333333');
        document.getElementsByTagName('body')[0].style.setProperty('--theme-99-to-66','#999999');
        document.getElementsByTagName('body')[0].style.setProperty('--theme-f6-to-2f','#f6f6f6');
        document.getElementsByTagName('body')[0].style.setProperty('--theme-ed-to-44','#ededed');
        document.getElementsByTagName('body')[0].style.setProperty('--theme-f6-to-00','#f6f6f6');
    }

    window.localforage.setItem('nightTheme', themeType)

    dispatch(createAction('updateAppSetting')({
        themeType: themeType
    }))

}

//  dispatch actions demo
export const demo = (setting) => dispatch => {
    dispatch(createAction('updateAppSetting')(setting))
}